<?php
/*
 * 公共入口文件
 */
final class HAPPYPHP{

    public static function run(){
        self::_const();
        self::crate_dir();
        self::_import_file();
        App::run();
    }


    /**
     * 设置系统常量
     */
    private static function _const(){
        //框架版本
        define("VER","1.0");
        // 系统常量定义
        $patc = str_replace("\\","/",__DIR__);
        //系统根目录
        define("ROOT_PATH",dirname($patc));
        //框架核心目录
        define('HAPPYPHP_PATH', ROOT_PATH . "/HAPPYPHP");
        define("CONFIG_PATH",HAPPYPHP_PATH . "/Config");
        define("DATA_PATH",HAPPYPHP_PATH . "/Data");
        define("LIB_PATH",HAPPYPHP_PATH . "/Lib");
        define("CORE_PATH",LIB_PATH . "/Core");
        define("FUNCTION_PATH",LIB_PATH . "/Function");
        //应用目录
        define("APP_PATH",ROOT_PATH . "/" .APP_NAME);
        define("APP_CONFIG_PATH",APP_PATH . "/Config");
        define("APP_CONTROLLER_PATH",APP_PATH . "/Controller");
        define("APP_VIEW_PATH",APP_PATH . "/View");
        define("APP_PUBLIC_PATH",APP_PATH . "/Public");
    }


    /**
     * 创建应用目录
     */
    private static function crate_dir(){
        $arr=[
            APP_PATH,
            APP_CONFIG_PATH,
            APP_CONTROLLER_PATH,
            APP_VIEW_PATH,
            APP_PUBLIC_PATH
        ];
        //创建文件
        foreach ($arr as $v){
            is_dir($v) or  mkdir($v, 0777, true);
        }
    }

    /**
     * 框架所需文件
     */
    private static function _import_file(){
        $arr=[
            FUNCTION_PATH . "/function.php",
            CORE_PATH . "/App.class.php",
        ];

        foreach ($arr as $v){
            require_once $v;
        }
    }
}

HAPPYPHP::run();
